package util.core;

public class SolveArray {
    public double[] stuff;
    public double num;
    public int gcd;

    public SolveArray(double[] stuff, double num) {
        this.num = num;
        this.stuff = stuff;
        gcd = -1;
    }

    public boolean equals(Object o) {
        if (!(o instanceof SolveArray)) {
            return false;
        }
        SolveArray c = (SolveArray) o;
        if (c.stuff.length != stuff.length) {
            return false;
        }
        int gcdThis = getGcd();
        int gcdThat = c.getGcd();
        for (int i = 0; i < stuff.length; i++) {
            if (Math.abs(stuff[i] / gcdThis - c.stuff[i] / gcdThat) > .0000001)
                return false;
        }

        return true;

    }

    public int getGcd() {
        if (gcd != -1) {
            return gcd;
        }
        for (double a : stuff) {
            if (a != 0) {
                if (gcd == -1) {
                    gcd = (int) Math.round(a);
                } else {
                    gcd = Equation.gcd(gcd, (int) Math.abs(Math.round(a)));
                }
            }
        }
        if (num != 0) {
            gcd = Equation.gcd(gcd, (int) Math.round(num));
        }
        return gcd;
    }
}
